#include <iostream>
#include <unistd.h>
#include <pthread.h>

using namespace std;

void *ThreadRoutine(void* args){
    pthread_detach( pthread_self() );
    int cnt = 0;
    while(true){
        cout << (char*)args << " : " << getpid() << endl;
        sleep(1);
        if(cnt++ == 4) break;
    }
    pthread_exit((void*)13);
}

int main(){

    pthread_t tid;
    pthread_create( &tid, nullptr, ThreadRoutine, (void*)"Thread test detach");

    sleep(2);           // 先等待一下，防止出现子线程先于主线程启动

    return 0;
}